package org.feng.vo;

import lombok.Data;
import org.feng.client.response.PlantImageClassifyResponse;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

/**
 * TODO
 *
 * @author feng
 */
@Data
public class PlantImageClassifyVO implements Serializable{

    private static final long serialVersionUID = 8632409199693519868L;

    private Long logId;

    private List<ResultData> result;

    @Data
    public static class ResultData implements Serializable {

        private static final long serialVersionUID = 3441826335265642806L;

        private String name;
        private BigDecimal score;
        private BaiKeInfo baiKeInfo;
    }

    public static PlantImageClassifyVO newInstance(PlantImageClassifyResponse response) {
        PlantImageClassifyVO vo = new PlantImageClassifyVO();

        vo.setLogId(response.getLogId());
        List<ResultData> resultDataList = new ArrayList<>();
        for (PlantImageClassifyResponse.Result resultData : response.getResult()) {
            ResultData result = new ResultData();
            result.setName(resultData.getName());
            result.setScore(resultData.getScore());

            org.feng.client.response.BaiKeInfo baiKeInfo = resultData.getBaiKeInfo();
            if (baiKeInfo != null) {
                BaiKeInfo baiKe = new BaiKeInfo();
                baiKe.setBaiKeUrl(baiKeInfo.getBaiKeUrl());
                baiKe.setImageUrl(baiKeInfo.getImageUrl());
                baiKe.setDescription(baiKeInfo.getDescription());
                result.setBaiKeInfo(baiKe);
            }
            resultDataList.add(result);
        }
        vo.setResult(resultDataList);
        return vo;
    }
}
